package wzr;
import java.awt.Container;
import java.awt.event.*;
import DataBase.*;
import javax.swing.*;
import wxy.DrawOnTheFrame;

import mainWindow.MainFrame;
public class AdjSenseBlock extends SenseBlock 
{
	public AdjSenseBlock(AdjSense as, boolean hl, int num)
	{
		super(as, hl, num);
		adjSense = as;
		initAdj();
	}
	private AdjSense adjSense;
	private void initAdj()
	{
		if (adjSense.hasSynonyms())
		{
			Box synonymsPanel = Box.createVerticalBox();
			//synonymsPanel.setLayout(new BoxLayout(synonymsPanel, BoxLayout.Y_AXIS));
			Box[] str = new Box[adjSense.getSynonyms().size()];
			for (int i = 0; i < adjSense.getSynonyms().size(); i ++)
			{
				str[i] = Box.createHorizontalBox();
				//str[i].setLayout(new BoxLayout(str[i], BoxLayout.X_AXIS));
				str[i].add(new JLabel(i + 1 + "."));
				JLabel[] word = new JLabel[adjSense.getSynonyms().get(i).get_Words().size()];
				for (int j = 0; j < adjSense.getSynonyms().get(i).get_Words().size(); j ++)
				{
					word[j] = new JLabel(adjSense.getSynonyms().get(i).get_Words().get(j));
					final String newWord = word[j].getText();
					word[j].addMouseListener(new MouseAdapter()
					{
						public void mouseClicked(MouseEvent e) 
						{
							Container container = getTopLevelAncestor();
							if (container instanceof MainFrame)
							{
								((MainFrame)container).addWord(newWord);
							}
						}
					});
					str[i].add(word[j]);
					str[i].add(Box.createHorizontalStrut(20));
				}
				str[i].add(Box.createHorizontalGlue());
				synonymsPanel.add(str[i]);
			}
			synonymsPanel.add(Box.createVerticalGlue());
			synonymsPanel.setBackground(null);
			synonymsPanel.setOpaque(false);
			relation.addTab("Synonyms", synonymsPanel);
		}
		if (adjSense.hasAntonyms())
		{
			Box antonymsPanel = Box.createVerticalBox();
			//antonymsPanel.setLayout(new BoxLayout(antonymsPanel, BoxLayout.Y_AXIS));
			Box[] str = new Box[adjSense.getAntonyms().size()];
			for (int i = 0; i < adjSense.getAntonyms().size(); i ++)
			{
				str[i] = Box.createHorizontalBox();
				//str[i].setLayout(new BoxLayout(str[i], BoxLayout.X_AXIS));
				str[i].add(new JLabel(i + 1 + "."));
				JLabel[] word = new JLabel[adjSense.getAntonyms().get(i).get_Words().size()];
				for (int j = 0; j < adjSense.getAntonyms().get(i).get_Words().size(); j ++)
				{
					word[j] = new JLabel(adjSense.getAntonyms().get(i).get_Words().get(j));
					final String newWord = word[j].getText();
					word[j].addMouseListener(new MouseAdapter()
					{
						public void mouseClicked(MouseEvent e) 
						{
							Container container = getTopLevelAncestor();
							if (container instanceof MainFrame)
							{
								((MainFrame)container).addWord(newWord);
							}
						}
					});
					str[i].add(word[j]);
					str[i].add(Box.createHorizontalStrut(20));
				}
				str[i].add(Box.createHorizontalGlue());
				antonymsPanel.add(str[i]);
			}
			antonymsPanel.add(Box.createVerticalGlue());
			antonymsPanel.setBackground(null);
			antonymsPanel.setOpaque(false);
			relation.addTab("Antonyms", antonymsPanel);
		}
		if (adjSense.hasDerivationallyRelated())
		{
			Box derivationallyRelatedPanel = Box.createVerticalBox();
			//derivationallyRelatedPanel.setLayout(new BoxLayout(derivationallyRelatedPanel, BoxLayout.Y_AXIS));
			Box[] str = new Box[adjSense.getDerivationallyRelated().size()];
			for (int i = 0; i < adjSense.getDerivationallyRelated().size(); i ++)
			{
				str[i] = Box.createHorizontalBox();
				//str[i].setLayout(new BoxLayout(str[i], BoxLayout.X_AXIS));
				String type = new String();
				if (adjSense.getDerivationallyRelated().get(i).get_Type() == 1)
				{
					type = "(Noun)";
				}
				else
				{
					type = "(Verb)";
				}
				str[i].add(new JLabel(i + 1 + "." + type));
				JLabel[] word = new JLabel[adjSense.getDerivationallyRelated().get(i).get_Words().size()];
				for (int j = 0; j < adjSense.getDerivationallyRelated().get(i).get_Words().size(); j ++)
				{
					word[j] = new JLabel(adjSense.getDerivationallyRelated().get(i).get_Words().get(j));
					final String newWord = word[j].getText();
					word[j].addMouseListener(new MouseAdapter()
					{
						public void mouseClicked(MouseEvent e) 
						{
							Container container = getTopLevelAncestor();
							if (container instanceof MainFrame)
							{
								((MainFrame)container).addWord(newWord);
							}
						}
					});
					str[i].add(word[j]);
					str[i].add(Box.createHorizontalStrut(20));
				}
				str[i].add(Box.createHorizontalGlue());
				derivationallyRelatedPanel.add(str[i]);
			}
			derivationallyRelatedPanel.add(Box.createVerticalGlue());
			derivationallyRelatedPanel.setBackground(null);
			derivationallyRelatedPanel.setOpaque(false);
			relation.addTab("Derivationally Related", derivationallyRelatedPanel);
		}
		if (adjSense.hasAttribute())
		{
			Box attributesPanel = Box.createVerticalBox();
			//attributesPanel.setLayout(new BoxLayout(attributesPanel, BoxLayout.Y_AXIS));
			Box[] str = new Box[adjSense.getAttributes().size()];
			for (int i = 0; i < adjSense.getAttributes().size(); i ++)
			{
				str[i] = Box.createHorizontalBox();
				//str[i].setLayout(new BoxLayout(str[i], BoxLayout.X_AXIS));
				str[i].add(new JLabel(i + 1 + "."));
				JLabel[] word = new JLabel[adjSense.getAttributes().get(i).get_Words().size()];
				for (int j = 0; j < adjSense.getAttributes().get(i).get_Words().size(); j ++)
				{
					word[j] = new JLabel(adjSense.getAttributes().get(i).get_Words().get(j));
					final String newWord = word[j].getText();
					word[j].addMouseListener(new MouseAdapter()
					{
						public void mouseClicked(MouseEvent e) 
						{
							Container container = getTopLevelAncestor();
							if (container instanceof MainFrame)
							{
								((MainFrame)container).addWord(newWord);
							}
						}
					});
					str[i].add(word[j]);
					str[i].add(Box.createHorizontalStrut(20));
				}
				str[i].add(Box.createHorizontalGlue());
				attributesPanel.add(str[i]);
			}
			attributesPanel.add(Box.createVerticalGlue());
			attributesPanel.setBackground(null);
			attributesPanel.setOpaque(false);
			relation.addTab("Related Nouns", attributesPanel);
		}
		if (adjSense.hasUsage() || adjSense.hasRegion() || adjSense.hasUsage())
		{
			JTextPane domainPane = new JTextPane();
			domainPane.setBackground(null);
			domainPane.setOpaque(false);
			domainPane.setEditable(false);
			String tmp = new String("");
			if (adjSense.hasTopic())
			{
				tmp += "Topic: ";
				for (int i = 0; i < adjSense.getTopic().size(); i ++)
				{
					for (int j = 0; j < adjSense.getTopic().get(i).get_Words().size(); j ++)
					{
						if (j == adjSense.getTopic().get(i).get_Words().size() - 1)
						{
							tmp += (adjSense.getTopic().get(i).get_Words().get(j) + ";\n");
						}
						else
						{
							tmp += (adjSense.getTopic().get(i).get_Words().get(j) + " ");
						}
					}
				}
			}
			if (adjSense.hasRegion())
			{
				tmp += "Region: ";
				for (int i = 0; i < adjSense.getRegion().size(); i ++)
				{
					for (int j = 0; j < adjSense.getRegion().get(i).get_Words().size(); j ++)
					{
						if (j == adjSense.getRegion().get(i).get_Words().size() - 1)
						{
							tmp += (adjSense.getRegion().get(i).get_Words().get(j) + ";\n");
						}
						else
						{
							tmp += (adjSense.getRegion().get(i).get_Words().get(j) + " ");
						}
					}
				}
			}
			if (adjSense.hasUsage())
			{
				tmp += "Usage: ";
				for (int i = 0; i < adjSense.getUsage().size(); i ++)
				{
					for (int j = 0; j < adjSense.getUsage().get(i).get_Words().size(); j ++)
					{
						if (j == adjSense.getUsage().get(i).get_Words().size() - 1)
						{
							tmp += (adjSense.getUsage().get(i).get_Words().get(j) + ";\n");
						}
						else
						{
							tmp += (adjSense.getUsage().get(i).get_Words().get(j) + " ");
						}
					}
				}
			}
			domainPane.setText(tmp);
			relation.addTab("Domain", domainPane);
		}
		if (adjSense.hasAlsosees())
		{
			Box alsoseesPanel = Box.createVerticalBox();
			//alsoseesPanel.setLayout(new BoxLayout(alsoseesPanel, BoxLayout.Y_AXIS));
			Box[] str = new Box[adjSense.getAlsosees().size()];
			for (int i = 0; i < adjSense.getAlsosees().size(); i ++)
			{
				str[i] = Box.createHorizontalBox();
				//str[i].setLayout(new BoxLayout(str[i], BoxLayout.X_AXIS));
				str[i].add(new JLabel(i + 1 + "."));
				JLabel[] word = new JLabel[adjSense.getAlsosees().get(i).get_Words().size()];
				for (int j = 0; j < adjSense.getAlsosees().get(i).get_Words().size(); j ++)
				{
					word[j] = new JLabel(adjSense.getAlsosees().get(i).get_Words().get(j));
					final String newWord = word[j].getText();
					word[j].addMouseListener(new MouseAdapter()
					{
						public void mouseClicked(MouseEvent e) 
						{
							Container container = getTopLevelAncestor();
							if (container instanceof MainFrame)
							{
								((MainFrame)container).addWord(newWord);
							}
						}
					});
					str[i].add(word[j]);
					str[i].add(Box.createHorizontalStrut(20));
				}
				str[i].add(Box.createHorizontalGlue());
				alsoseesPanel.add(str[i]);
			}
			relation.addTab("Related Nouns", alsoseesPanel);
		}
	}
}
